<template>
	<view class="content">
		<view class="block classify-tab-block">
			<view class="tab-content">
				<view class="active tab-item">推荐{{pageType}}</view>
				<!-- <view @click="goCircle" class="tab-item">职友圈</view> -->
			</view>
		</view>
		<template v-if="list.length>0">
			<view v-if="identity==1" class="block list-block">
				<view @click="navigate('/page_other/job_hunting/job_detail/index?id='+item.id+'&jobType='+item.jobType)"
					class="list-item" v-for="(item,index) in list" :key="item.id">
					<view class="list-info">
						<view class="title">{{item.jobTitle}}</view>
						<view class="address iconfont icon-dizhi">{{item.jobAddress}}</view>
						<view class="label-block">
							<view class="label-item" v-for="label in item.label">{{label}}</view>
						</view>
						<view class="wage">{{item.minSalary}}-{{item.maxSalary}}<text class="unit">元</text></view>
					</view>
					<view class="detail-info">
						<view class="name">{{item.comRecruiters.comPosition}}</view>
						<image mode="aspectFill" :src="item.comRecruiters.user.faceUrl" class="photo"></image>
						<view class="apply-btn">申请</view>
					</view>
				</view>
			</view>
			<view v-if="identity==2" class="block list-block">
				<view @click="goView(item.id)" class="list-item person-item" v-for="(item,index) in list"
					:key="item.id">
					<view class="info-block">
						<image :src="item.user.faceUrl?item.user.faceUrl:imageUrl+'/job_hunting/home/Mr.png'"
							class="user-photo"></image>
						<view class="info">
							<view class="name">{{item.realName}}</view>
							<view class="other-item">
								<view class="other">{{item.birthday}}岁 / </view>
								<view class="other"> {{item.educationText}} / </view>
								<view class="other" v-if="item.workTimeStart!=='0年'">
									{{item.workTimeStart}}经验 /
								</view>
								<view class="other" v-if="item.workTimeStart=='0年'">经验小于1年 / </view>
								<view class="other"> {{item.jobText}}</view>
							</view>
						</view>
					</view>
					<view class="job-block">
						<view class="job">
							<view class="job-content">
								<view class="jobList">
									<text class="darkgray" style="margin-right:10rpx;">想找</text>
									{{item.regArea}} / {{item.postName}} / {{item.salaryMin}}-{{item.salaryMax}}元
								</view>
							</view>
						</view>
						<view class="btn-block">
							<view class="btn" @click.stop="goChat(item.user.mobile)">沟通</view>
						</view>
					</view>
				</view>
			</view>
		</template>
		<view v-else-if="list.length>0&&!more" style="text-align: center;">没有更多了哦</view>
		<view v-else style="text-align: center;">暂无数据</view>
		<LoadingTips v-if="showLoading" :imageUrl="imageUrl" :type="1"></LoadingTips>
	</view>
</template>

<script>
	import {
		getCustomerListApi,
		getPublishApi
	} from '@/api/job_hunting.js';
	import {
		isMore
	} from '@/util/util.js';
	import {
		sendHiMessage
	} from '@/util/im.js'
	export default {
		data() {
			return {
				imageUrl: '',
				pageType: '',

				list: [],
				page: 1,
				limit: 10,
				more: true,
				total: 0,
				showLoading: false,
			}
		},
		methods: {
			navigate(url) {
				uni.navigateTo({
					url
				})
			},
			goCircle() {
				uni.redirectTo({
					url: '/page_other/circle/index'
				})
			},
			goView(id) {
				uni.navigateTo({
					url: '/page_other/resume/index?type=view&id=' + id
				})
			},
			goChat(mobile) {
				if (this.identity == 2) {
					uni.$on('chooseChatPosition', (e) => {
						uni.$off('chooseChatPosition');
						uni.showLoading({
							title: '发送中',
							mask: true
						})
						try {

							sendHiMessage('你好！', mobile, e).finally(() => {
								uni.hideLoading()
								this.showToast('发送成功')
							})
						} catch (e) {
							uni.hideLoading()
						}
					})
					uni.navigateTo({
						url: '/page_other/choose_position/choose_position'
					})
				}
			},
			async getList(refresh = false) {
				if (this.more) {
					let config = {
						page: this.page,
						limit: this.limit
					}
					this.showLoading = true
					let res = this.$store.getters.identity == 1 ? await getPublishApi(config) :
						await getCustomerListApi(config);
					this.showLoading = false;
					let list = res.list ?? [];
					this.list = refresh ? list : [...this.list, ...list];
					if (this.list.length > 0 && this.page == 1) {
						this.showToast("系统已自动为您匹配合适的" + this.pageType);
					};
					this.total = res.count
					this.more = isMore(this.page, this.limit, this.total)
				}
			}
		},
		computed: {
			identity() {
				return this.$store.getters.identity
			}
		},
		onShow() {
			this.imageUrl = this.globalConfig.imageUrl;
			this.pageType = this.identity == 1 ? '职位' : '求职者';

			this.getList(true);
		},

		onPullDownRefresh() {
			this.refresh();
			uni.stopPullDownRefresh();
		},
		onReachBottom() {
			if (this.more) {
				this.page++;
				this.getList()
			}
		},
	}
</script>

<style lang="scss">
	$box-shadow: 0 0 10px 0 #efefef;

	page {
		background: #FAFAFA;
	}

	.content {
		width: 100%;

		.loadingicon {
			width: 100%;
			height: 80rpx;
			display: flex;
			flex-wrap: wrap;
			align-items: center;
			justify-content: center;
		}

		.loading {
			width: 100%;
			height: 100rpx;
			line-height: 100rpx;
			align-items: center;
			justify-content: center;
			position: relative;
			text-align: center;
		}

		.loading .line {
			position: absolute;
			width: 450rpx;
			left: 150rpx;
			top: 50rpx;
			height: 1px;
			border-top: 1px solid #eee;
		}

		.loading .text {
			position: relative;
			display: inline-block;
			padding: 0 20rpx;
			background: #fff;
			z-index: 2;
			color: #777;
		}

		.loadingicon .loading {
			animation: load linear 1s infinite;
			font-size: 45rpx;
			color: #000;
		}

		.loadingicon {
			width: 100%;
			height: 80rpx;
		}

		//padding: 30rpx;
		.tips {
			width: 70%;
			padding: 10rpx 20rpx;
			margin: auto;
			background-color: #ff7626;
			color: #fff;
			text-align: center;
			font-size: 28rpx;
			border-radius: 60rpx;

		}

		.block {
			width: 100%;
			padding: 20rpx 30rpx;
			margin-bottom: 20rpx;
			position: relative;
		}

		.block.classify-tab-block {
			width: 100%;
			height: 100rpx;
			background-color: #fff;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: space-between;

			.tab-content {
				display: flex;
				flex-direction: row;
				justify-content: left;

				.tab-item {
					padding: 10rpx 30rpx;
					font-weight: bold;
					font-size: 36rpx;
					margin-right: 20rpx;
					flex: none;
				}

				.tab-item.active {
					background: url("https://job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/job_hunting/home/tab_selected_bg.png") no-repeat right bottom;
					background-size: 70%;
				}
			}

			.publish-btn {
				width: 45rpx;
			}

			.iconfont {
				font-size: 32rpx;
				font-weight: bold;
				color: #000;
			}
		}

		.block.label-block {
			width: 100%;
			display: flex;
			flex-direction: row;
			justify-content: left;
			align-items: center;

			.label-content {
				width: calc(100% - 110rpx);
				display: flex;
				flex-direction: row;
				justify-content: left;
				align-items: center;

				.label-item {
					padding: 10rpx 30rpx;
					font-size: 28rpx;
					color: #999;
					background: #F3F3F3;
					margin-right: 20rpx;
				}

				.label-item.active {
					color: #FE7526;
					background: #FDECE5;
				}

			}

			.font-text {
				font-size: 28rpx;
			}

			.iconfont {
				font-size: 38rpx;
				font-weight: bold;
				margin-right: 10rpx;
			}
		}

		.block.list-block {
			box-shadow: none;
			display: flex;
			flex-direction: column;
			margin-bottom: 0;

			.list-item {
				width: 100%;
				background: #fff;
				border-radius: 10rpx;
				box-shadow: $box-shadow;
				padding: 20rpx;
				display: flex;
				flex-direction: row;
				justify-content: center;
				margin-bottom: 20rpx;

				.detail-info {
					width: 180rpx;
					height: 200rpx;
					display: flex;
					flex-direction: row;
					flex-wrap: wrap;
					justify-content: center;
					align-items: center;

					.name {
						width: 110rpx;
						font-size: 24rpx;
						color: #999;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
						text-align: center;
						text-indent: 20rpx;
					}

					.photo {
						width: 70rpx;
						height: 70rpx;
						border-radius: 100%;
						background: #efefef;
					}

					.apply-btn {
						border: 1px solid #FE7526;
						border-radius: 8rpx;
						color: #FE7526;
						font-size: 24rpx;
						padding: 8rpx 28rpx;
						position: relative;
						left: 30rpx;
					}
				}

				.list-info {
					width: calc(100% - 180rpx);
					display: flex;
					flex-direction: column;

					view {
						width: 100%;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}

					.title {
						color: #000;
						font-weight: bold;
						font-size: 34rpx;
					}

					.address {
						color: #999;
						font-size: 26rpx;
						margin-top: 20rpx;
					}

					.label-block {
						font-size: 24rpx;
						display: flex;
						flex-direction: row;
						flex-wrap: wrap;
						justify-content: left;
						margin-top: 20rpx;

						.label-item {
							padding: 8rpx 20rpx;
							background: #F5F6F8;
							color: #999;
							margin: 0 10rpx 20rpx 0;
						}
					}

					.wage {
						color: #FE7526;
						font-size: 36rpx;
						font-weight: bold;

						.unit {
							font-size: 28rpx;
							font-weight: normal;
						}
					}
				}
			}

			.list-item:last-child {
				margin-bottom: 0;
			}

			.person-item {
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				padding: 0 30rpx;
				margin-bottom: 30rpx;

				.info-block,
				.job-block {
					width: 100%;
					padding: 20rpx 0;
				}

				.info-block {
					border-bottom: 1px solid #efefef;
					display: flex;
					flex-direction: row;
					align-items: center;

					.user-photo {
						width: 100rpx;
						height: 100rpx;
						border-radius: 50%;
					}

					.info {
						width: calc(100% - 120rpx);
						margin-left: 20rpx;
						font-size: 26rpx;

						.name {
							font-weight: bold;
							font-size: 34rpx;
						}

						.other-item {
							display: flex;
							flex-direction: row;

							.other {
								color: #999;
								margin-top: 14rpx;
								overflow: hidden;
								text-overflow: ellipsis;
								white-space: nowrap;
							}
						}

					}
				}

				.job-block {
					display: flex;
					flex-direction: row;
					align-items: center;

					.job {
						width: calc(100% - 140rpx);
						display: flex;
						flex-direction: column;
						justify-content: center;

						.label-block {
							width: 100%;
							display: flex;
							flex-direction: row;
							flex-wrap: wrap;

							.label-item {
								background: #F4F5F7;
								color: #999;
								font-size: 24rpx;
								padding: 4rpx 10rpx;
								margin-right: 20rpx;
								margin-bottom: 20rpx;
							}
						}

						.job-content {
							width: 100%;
							font-size: 26rpx;
						}
					}

					.btn-block {
						width: 140rpx;
						display: flex;
						align-items: center;
						justify-content: center;

						.btn {
							padding: 6rpx 26rpx;
							border: 1px solid #FE7526;
							border-radius: 6rpx;
							color: #FE7526;
							font-size: 24rpx;
						}
					}
				}
			}

			.person-item:last-child {
				margin-bottom: 0;
			}

			.circle-item {
				display: flex;
				flex-direction: column;
				padding: 30rpx 30rpx 15rpx 30rpx;

				.info-block {
					display: flex;
					align-items: center;

					.user-photo {
						width: 70rpx;
						border-radius: 35rpx;
						margin-right: 15rpx;
					}

					.name {
						width: calc(100% - 70rpx - 15rpx);
						font-size: 30rpx;
					}
				}

				.content-block {
					font-size: 30rpx;
					padding: 15rpx 0 0rpx 0;

					.part-content {
						line-height: 50rpx;
						display: -webkit-box;
						overflow: hidden;
						/*超出隐藏*/
						text-overflow: ellipsis;
						/*隐藏后添加省略号*/
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 3; //想显示多少行

						.keyword {
							color: #0b93e1;
						}

						.aite {
							color: #0b93e1;
						}
					}

					.content {
						line-height: 50rpx;

						.keyword {
							color: #0b93e1;
						}

						.aite {
							color: #0b93e1;
						}
					}

					.all {
						width: 60rpx;
						;
						margin-top: 10rpx;
						color: #ff7626;
					}
				}

				.video-block {
					width: 100%;

					.video-item {
						width: 400rpx;
						height: 300rpx;
					}
				}

				.operate-block {
					display: flex;
					flex-direction: row;
					justify-content: space-between;
					align-items: center;

					.time {
						color: #999999;
						font-size: 28rpx;
					}

					.operate {
						display: flex;
						align-items: center;
						height: 70rpx;

						.operate-item {
							width: 320rpx;
							height: 70rpx;
							border-radius: 6rpx;
							background-color: #616161;
							display: flex;
							flex-direction: row;

							.item {
								width: calc(100% / 2 - 1px);
								display: flex;
								flex-direction: row;
								align-items: center;
								justify-content: center;
								border-right: 1px solid rgba(0, 0, 0, .1);

								.operate-icon {
									width: 30rpx;
									margin-right: 5rpx;
								}

								.operate-name {
									font-size: 28rpx;
									color: #ccc;
								}
							}

							.item:last-child {
								border: 0;
							}
						}

						.icon {
							width: 65rpx;
							margin-left: 10rpx;
						}
					}

				}

				.comment-block {
					background-color: #f0f0f0;
					border-radius: 6rpx;
					padding: 20rpx;
					margin-top: 10rpx;
					display: flex;
					flex-direction: column;

					.like-item {
						width: 100%;
						margin: auto;

						.like-icon {
							width: 35rpx;
							position: relative;
							top: 4rpx;
						}

						.name {
							font-size: 28rpx;
							color: #0b92e0;
							margin-left: 7rpx;
						}

						.comma {
							color: #0b92e0;
						}
					}

					.divide-line {
						padding-bottom: 20rpx;
						border-bottom: 1px solid #ccc;
					}

					.comment-list {
						display: flex;
						flex-direction: column;
						padding-top: 10rpx;

						.comment-item {
							.content {
								font-size: 30rpx;
								line-height: 50rpx;
								display: -webkit-box;
								overflow: hidden;
								/*超出隐藏*/
								text-overflow: ellipsis;
								/*隐藏后添加省略号*/
								-webkit-box-orient: vertical;
								-webkit-line-clamp: 3; //想显示多少行

								.name {
									color: #0b92e0;
								}
							}
						}
					}
				}
			}
		}
	}
</style>